package com.kailing.bootBatch.quartz;

import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;

/**
 * <h3>partitionjob</h3>
 * <p>demo job1</p>
 *
 * @author : hduong
 * @version : 1.0
 * @date : 2019-12-18 16:42
 **/
public class DemoJob1 {
    public static void main(String[] args) throws SchedulerException {
        JobDetail jobDetail = JobBuilder.newJob(MyJob.class)
                .withIdentity("job1", "job1Group")
                .usingJobData("hongdu", "洪都的job1测试")
                .usingJobData("moon", 5.21F)
                .build();

        //定义触发器
        Trigger trigger = TriggerBuilder.newTrigger()
                .withIdentity("trigger1", "trigger1Group")
                .startNow()
                .withSchedule(SimpleScheduleBuilder.simpleSchedule()
                        .withIntervalInSeconds(2)
                        //永远重复
                        .repeatForever()
                    ).build();

        //DirectSchedulerFactory StdSchedulerFactory 工厂模式
        SchedulerFactory schedulerFactory =new StdSchedulerFactory();

        //通过工厂获取调度器
        Scheduler scheduler = schedulerFactory.getScheduler();

        //注册 绑定
        scheduler.scheduleJob(jobDetail, trigger);
        scheduler.start();

    }
}
